package service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.github.miemiedev.mybatis.paginator.domain.Paginator;

import appmodel.OrderListParams;
import dao.OrderMapper;
import model.Order;
import service.OrderService;

@Service
@SuppressWarnings({ "rawtypes", "unchecked" })
public class OrderServiceImpl implements OrderService{

	@Autowired
	OrderMapper orderMapper;
	
	@Override
	public List<Order> getOrderList(OrderListParams orderListParams) {
		return orderMapper.getOrderList(orderListParams);
	}
	
	@Override
	public List<Order> getMyOrderList(OrderListParams orderListParams) {
		return orderMapper.getMyOrderList(orderListParams);
	}

	@Override
	public Order getOrderDetail(String orderId) {
		return orderMapper.getOrderDetail(orderId);
	}

	@Override
	public void modifyOrderState(Map<String,Object> map) {
		orderMapper.modifyOrderState(map);
	}

	@Override
	public long getOrderAllNumber(long userId) {
		return orderMapper.getOrderAllNumber(userId);
		
	}

	@Override
	public long getOrderSuccessNumber(long userId) {
		return orderMapper.getOrderSuccessNumber(userId);
	}

	@Override
	public long getOrderFailNumber(long userId) {
		return orderMapper.getOrderFailNumber(userId);
	}

	@Override
	public long getOrderIngNumber(long userId) {
		return orderMapper.getOrderIngNumber(userId);
	}

	public int insert(Order order) {
		return orderMapper.insert(order);
	}

	@Override
	public int cancelOrder(Order order) {
		return orderMapper.cancelOrder(order);
	}

	@Override
	public List<Order> getUserOrderList(OrderListParams orderListParams) {
		return orderMapper.getUserOrderList(orderListParams);
	}

	@Override
	public Map selectAll(PageBounds pageBounds, Map mapValue) {
		List userList = this.orderMapper.selectAll(pageBounds, mapValue);
		Map map = new HashMap();
		if (userList.size() > 0) {
			PageList pageOrders = (PageList) userList;

			Paginator paginator = pageOrders.getPaginator();
			map.put("list", pageOrders);
			map.put("paginator", paginator);
		}
		return map;
	}

}
